package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.Restaurant;
import com.ruoyi.system.domain.RestaurantOrder;
import com.ruoyi.system.service.IRestaurantOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * 餐饮订单Controller
 *
 * @author 强盛酒店
 * @date 2023-03-12
 */
@RestController
@RequestMapping("/system/restaurantOrder")
public class RestaurantOrderController extends BaseController {
    @Autowired
    private IRestaurantOrderService restaurantOrderService;

    /**
     * 查询餐饮订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RestaurantOrder restaurantOrder) {
        startPage();
        List<RestaurantOrder> list = restaurantOrderService.selectRestaurantOrderList(restaurantOrder);
        return getDataTable(list);
    }

    @GetMapping("/my")
    public TableDataInfo getMyOrder() {
        startPage();
        List<RestaurantOrder> list = restaurantOrderService.getMyOrder();
        return getDataTable(list);
    }

    /**
     * 获取餐饮订单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(restaurantOrderService.selectRestaurantOrderById(id));
    }

    /**
     * 新增餐饮
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody List<Restaurant> restaurantList) {
        return toAjax(restaurantOrderService.insert(restaurantList));
    }

    /**
     * 新增餐饮订单
     */
    @PostMapping
    public AjaxResult add(@RequestBody RestaurantOrder restaurantOrder) {
        return toAjax(restaurantOrderService.insertRestaurantOrder(restaurantOrder));
    }

    @PutMapping("/audit/{id}")
    public AjaxResult audit(@PathVariable("id") Long id) throws ParseException {
        return toAjax(restaurantOrderService.auditRestaurantOrder(id));
    }

    @PutMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable("id") Long id) {
        return toAjax(restaurantOrderService.cancel(id));
    }

    /**
     * 修改餐饮订单
     */
    @PutMapping
    public AjaxResult edit(@RequestBody RestaurantOrder restaurantOrder) {
        return toAjax(restaurantOrderService.updateRestaurantOrder(restaurantOrder));
    }

    /**
     * 删除餐饮订单
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(restaurantOrderService.deleteRestaurantOrderByIds(ids));
    }
}
